<?php
/**
 *  
 * @package package_name
 * @author Mervin.Wong<mervin0502@163.com>
 * @copyright
 * @license  http://www.apache.org/licenses/LICENSE-2.0
 * @version 0.1.0
 * @date 2013-3-1下午8:05:31
 *
 */
 
 /**
  * CanGoo Comment Model
  * 评论模型
  * @package blog
  * @subpackage models
  * @category library
  * @author mervin.wong<mervin0502@163.com>
  * @link http://mervin.me/project/cangoo description
  */
  class Comment_model extends CI_Model{
  	
  	public function __construct(){
  		parent::__construct();
  		$this->load->database();
  		
  	}
  	
  	/**
  	 * 获取多条记录
  	 * @access public
  	 * @param array $field $table field
  	 * @param string $table table name
  	 * @param array $conditions sql where 
  	 * @return array description
  	 */
  	public function get_all($field, $table, $conditions, $orderby){
  		$this->db->select($field);
  		$this->db->from($table);
  		foreach($conditions as $k=>$v){
  			$this->db->where($k,$v);
  		}
  		foreach($orderby as $k=>$v){
  			$this->db->order_by($k,$v);
  		}
  		$query = $this->db->get();
  		return $query->result_array();
  	}
  	
  	/**
  	 * 获取一条记录
  	 * @access public
  	 * @param array $field $table field
  	 * @param string $table table name
  	 * @param array $conditions sql where 
  	 * @return array description
  	 */
  	public function get_one($field, $table, $conditions){
   		$this->db->select($field);
  		$this->db->from($table);
  		foreach($conditions as $k=>$v){
  			$this->db->where($k,$v);
  		}
  		$query = $this->db->get();
  		return $query->row(); 		
  	}
  	/**
  	 * 插入一条记录
  	 * @access public
  	 * @param string $table table name
  	 * @param array $data field value
  	 * @return int|bool description
  	 */
  	public function insert($table, $data){
  		$this->db->insert($table, $data);
  		if($this->db->affected_rows() > 0){
  			return $this->db->insert_id();
  		}else{
  			return false;
  		}
  	}
  	
  	/**
  	 * 判断某篇文章下是否存在评论内容
  	 * @access public
  	 * @param int $pid blog_post pid
  	 * @return bool description
  	 */
  	public function is_have($field, $table, $conditions){
  		$this->db->select($field);
  		$this->db->from($table);
  		foreach($conditions as $k=>$v){
  			$this->db->where($k, $v);
  		}
  		$query = $this->db->get();
  		if($query->num_rows > 0){
  			return true;
  		}else{
  			return false;
  		}
  	}
  }
  
/* End of file comment_model.php */
/* Location:./apss/blog/models/comment_model.php */
